<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title></title>
		<link href="../../../js/bootstrap-3.3.7-dist/css/bootstrap.min.css" rel="stylesheet">
		<link rel="stylesheet" type="text/css" href="../../../css/reset.css" />
		<link rel="stylesheet" type="text/css" href="../../../css/footer.css" />
		<link rel="stylesheet" type="text/css" href="../../../css/classfly.css" />
		<style type="text/css">
			/*修改底部字体颜色*/
			
			.foot:nth-child(2) {
				color: #e83023;
			}
			
			.itemHref {
				width: 100%;
				height: 100%;
				display: block;
				padding-bottom: 10px;
			}
			
			.address {
				overflow: hidden;
				text-overflow: ellipsis;
				white-space: nowrap;
				position: relative;
				height: auto;
				z-index: 2;
			}
			.class2{
				width: 100%;
				text-align: center;
				padding: 0.069444rem 0.138888rem;
				/*border-top: 1px solid red;*/
				color: red;
				font-size: 13px;
				margin: 0 0 0.4rem 0;
			}
		</style>
		<script src="../../../js/flexible.min.js" type="text/javascript" charset="utf-8"></script>

	</head>

	<body>
		<div id="wrap">
			<div id="main">
				<div id="header">
					<a id="headImg" href="../colalition.html"><img class="headImg" src="../../../images/12.png" /></a>
					<p id="headTitle">分类</p>
				</div>
				<div id="content">
					<div class="search">
						<input type="text" class="search-input" id="searchShopName" />
						<div class="horizon"></div>
					</div>
					<div class="recommend">
						<p>为您推荐</p>
					</div>
					<div class="wrapper">
						<div class="content-left">
							<ul>

							</ul>
						</div>
						<div class="content-right">
						</div>
					</div>
				</div>
			</div>
			<div id="foot" class="row">
				<a class="foot col-xs-3 col-sm-3" href="../../kaoqin/index2.html">
					<img class="footImg" src="../../../images/15.png" />
					<p>管理</p>
				</a>
				<a class="foot col-xs-3 col-sm-3" href="../colalition.html">
					<img class="footImg" src="../../../images/14.png" />
					<p>联盟</p>
				</a>
				<a class="foot col-xs-3 col-sm-3" href="../../store/store.html">
					<img class="footImg" src="../../../images/11.png" />
					<p>商城</p>
				</a>
				<a class="foot col-xs-3 col-sm-3" href="../../personage/personIndex.html">
					<img class="footImg" src="../../../images/13.png" />
					<p>我的</p>
				</a>
			</div>
		</div>
	</body>
	<script src="../../../js/jquery-2.2.3.min.js"></script>
	<script src="../../../js/bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>
	<script src="../../../js/rhAdmin.js" type="text/javascript" charset="utf-8"></script>
	<script>
		// 获取左侧一级列表数据
		$().ready(function() {
			//获取url后值
			function getQueryString(name) {
				var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
				var r = window.location.search.substr(1).match(reg);
				if(r != null) {
					return unescape(r[2]);
				}
				return null;
			}

			$.ajax({
				type: "GET",
				url: "http://47.104.13.109/mall-service/lolcart/oneList",
				success: function(data) {
					//					console.log(data);
					$.each(data, function(idx, item) {
						var tpl = '<li class="menu" data-index="' + item.catId + '">' + item.name + '</li>';
						$('.content-left ul').append(tpl);
//						console.log(item.name);
						//						if(getQueryString('classfly') == item.name) {
						//							$('.content-left ul li:nth-child(' + idx + ')').addClass("active");
						//						} else {
						//							$('.content-left ul li:nth-child(1)').addClass("active");
						//						}

					})
					if(getQueryString('classfly')) {
						if($('.content-left ul li').length > 0) {
							//							alert(456);
							for(var i = 0; i < $('.content-left ul li').length; i++) {
								if(getQueryString('classfly') == $('.content-left ul li:nth-child(' + i + ')').html()) {
									$('.content-left ul li').eq(i - 1).addClass("active").siblings().removeClass("active");
									getrigth_menu($('.content-left ul li').eq(i - 1).attr('data-index'));
									break;
								}
							}
						}
					} else {
						$('.content-left ul li:nth-child(1)').addClass("active");
						getrigth_menu($('.content-left ul li:nth-child(1)').attr('data-index'));
					}
//					console.log(getQueryString('classfly'));
						//					for (var i = 0;i < data.length;i++) {
						//						if (data.list[i].name == getQueryString('classfly')) {
						//							$('.content-left ul li:nth-child('+i+')').addClass("active");
						//							break
						//						}
						//					}

				}
			})

			//获取右侧商品(二级菜单)数据

			function getrigth_menu(id) {

				$.ajax({
					type: "GET",
					url: "http://47.104.13.109/mall-service/lolcart/twoList",
					data: {
						cartId: id
					},
					success: function(data) {
//						console.log(data);
						var catIdOne = [];
						var catName=[];
						$('.content-right').html('');
						var tmp_right = '';
						for(var i = 0; i < data.length; i++) {
//							if(data[i].catId) {
//								catIdOne += data[i].catId + ','
//							}
							catIdOne[i]=data[i].catId;
							catName[i]=data[i].name;
						}
//						console.log(catName);
						
						if(catIdOne.length!=0) {
							$.each(data, function(idx, item) {
								console.log(catName[idx]);
								// 获取商铺 
									$.ajax({
										type: "get",
										url: "http://47.104.13.109/mall-service/shop/listCat2",
										async: true,
										data: {
											pageNum: 1,
											pageSize: 10,
											catId: catIdOne[idx]
										},
										success: function(res1) {
											if(res1.list.length>0){
												$('.content-right').append("<div class='class2'><span style='background: #f7f7f7;padding: 0 15px;font-weight: bold;'>"+catName[idx]+"</span><div style='width:50%;height:1px; background: #e83023;margin: 0 auto;margin-top: -5px;'></div></div>");
												$.each(res1.list, function(idx, item) {
													var tmp_right =
														'<div class="item"><a class="itemHref" href="../commodity_details/commodity_details.html?shopId=' + item.shopId + '">' +
														'<span class="item-title">' + item.shopName + '</span>' +
														'<img class="item-pic" style="height:4.1rem" src="' + item.shopPic + '"/>' +
														'<p class="address" ><img class="icon" src="../../../images/coalltion/newadress.png">' + item.shopAdd + ' </p>' +
														'<p class="present"><img class="icon" src="../../../images/coalltion/08.png">' + item.shopSign + '</p>' +
														'</a></div>';
													$('.content-right').append(tmp_right);
												});
											}
											
	
										}
									});
							})
						}
						//						

					}
				})
			}
			// 点击左侧此单切换样式，右侧回到顶部
			$(".content-left ul").on('click', 'li', function() {
				$(this).addClass('active').siblings().removeClass('active');
				$('.content-right').scrollTop(0);
				var idx = $(this).data('index');
				getrigth_menu(idx);
			})

			// 搜索
			function search() {

				$.ajax({
					type: "get",
					url: "http://47.104.13.109/mall-service/lolcart/oneList",
					async: true,
					success: function(res1) {
						// console.log(res1)
						//二级列表
						var str = '1';
						var str1 = '';
						$.each(res1, function(idx1, item1) {
							$.ajax({
								type: "get",
								url: "http://47.104.13.109/mall-service/lolcart/twoList?cartId=" + item1.catId,
								async: true,
								success: function(res2) {
//									console.log(res2);
									var str = '';
									$.each(res2, function(idx2, item2) {
										str += item2.catId + ','
									})
									if(str != '') {
										$.ajax({
											type: "get",
											url: "http://47.104.13.109/mall-service/shop/listCat2",
											async: true,
											data: {
												catId: str,
												shopName: $(".search-input").val(),
												pageNum: '1',
												pageSize: '10'
											},
											success: function(res3) {
//												console.log(res3)
												$.each(res3.list, function(idx3, item3) {
													str1 +=
														'<div class="item"><a class="itemHref" href="../commodity_details/commodity_details.html?shopId=' + item3.shopId + '">' +
														'<span class="item-title">' + item3.shopName + '</span>' +
														'<img class="item-pic" style="height:4.1rem" src="' + item3.shopPic + '"/>' +
														'<p class="address" ><img class="icon" src="../../../images/coalltion/07.png">' + item3.shopAdd + ' </p>' +
														'<p class="present"><img class="icon" src="../../../images/coalltion/08.png">' + item3.shopSign + '</p>' +
														'</a></div>';
													$('.content-right').html(str1);

												});

											}
										});
									}

								}
							});

						});

					}
				});
			}

			$(".search-input").on('keyup', function(e) { //当按下按键时  
				if(e.which == 13) {
					var shopName = document.getElementById("searchShopName").value;
					if(shopName != null){
						window.location.href="../nearby/searchshop.html?"+shopName;
					}
				}
			});
			//			$(".search-input").
		})
	</script>

</html>